package org.xteam.engine.object;

import java.awt.Color;
import java.awt.Point;

import org.xteam.engine.Camera;
import org.xteam.engine.FrameBuffer;
import org.xteam.engine.geom.Matrix;
import org.xteam.engine.geom.Point3D;

public class Triangle extends GraphicalObject {
	
	private Point3D p1;
	private Point3D p2;
	private Point3D p3;
	
	private Color p1Color = Color.black;
	private Color p2Color = Color.black;
	private Color p3Color = Color.black;
	
	public Triangle(Point3D p1, Point3D p2, Point3D p3) {
		this.p1 = p1;
		this.p2 = p2;
		this.p3 = p3;
	}

	public void applyTransform(Matrix matrix) {
		p1 = matrix.mutiply(p1);
		p2 = matrix.mutiply(p2);
		p3 = matrix.mutiply(p3);
	}

	@Override
	public void project(FrameBuffer frameBuffer, Camera camera) {
		Point pp1 = camera.getMatrix().mutiply(p1).project(camera);
		Point pp2 = camera.getMatrix().mutiply(p2).project(camera);
		Point pp3 = camera.getMatrix().mutiply(p3).project(camera);
		frameBuffer.drawLine(pp1, pp2);
		frameBuffer.drawLine(pp2, pp3);
		frameBuffer.drawLine(pp3, pp1);
	}
}
